﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ComponentModel;

using System.Reflection;


namespace city7
{
    namespace plp_enum
    {
        enum plp
        {
            [Description("Ответственный, тот кто ввел пароль")]
            o_l_0 = 0,
            [Description("Активный сервер: 1")]
            server_1 = 1,
            [Description("Путь к файлу mdb")]
            path_to_mdb_2 = 2,
            [Description("default_3 элемент")]
            default_3 = 3,
            [Description("currentMode_CutPaste_4 элемент")]
            currentMode_CutPaste_4 = 4,
            [Description("period_s_5 элемент")]
            period_s_5 = 5,
            [Description("period_p_6 элемент")]
            period_p_6 = 6,
            [Description("day_work_7 элемент")]
            day_work_7 = 7,
            [Description("hasData_s_8 элемент")]
            hasData_s_8 = 8,
            [Description("hasData_p_9 элемент")]
            hasData_p_9 = 9,
            [Description("raz_pol_10 элемент")]
            raz_pol_10 = 10,
            [Description("pass_11 элемент")]
            pass_11 = 11,
            [Description("task_12 элемент")]
            task_12 = 12,
            [Description("listAnyEdit_modeFAED_103 элемент")]
            listAnyEdit_modeFAED_103 = 103,
            [Description("Первый элемент")]
            listAnyEdit_cod_104 = 104,
            [Description("listAnyEdit_name_105 элемент")]
            listAnyEdit_name_105 = 105,
            [Description("listAnyEdit_text_106Первый элемент")]
            listAnyEdit_text_106 = 106,
            [Description("listAnyEdit_1_146 элемент")]
            listAnyEdit_1_146 = 146,
            [Description("listAnyEdit_addname_147 элемент")]
            listAnyEdit_addname_147 = 147,
            [Description("listAnyEdit_so_148 элемент")]
            listAnyEdit_so_148 = 148,
            [Description("zakaz_current_13 элемент")]
            zakaz_current_13 = 13,
            [Description("treeView_select_14 элемент")]
            treeView_select_14 = 14,
            [Description("zakaz_plase_current_15 элемент")]
            zakaz_plase_current_15 = 15,
            [Description("path_progr_files_16 элемент")]
            path_progr_files_16 = 16,
            [Description("zakaz_kol_17 элемент")]
            zakaz_kol_17 = 17,
            [Description("zakaz_select_ct_18 элемент")]
            zakaz_select_ct_18 = 18,
            [Description("zakaz_td_cod123_19 элемент")]
            zakaz_td_cod123_19 = 19,
            [Description("sir_current_doc_20 элемент")]
            sir_current_doc_20 = 20,
            [Description("sir_current_doc_cod123_21 элемент")]
            sir_current_doc_cod123_21 = 21,
            [Description("Первый элемент")]
            sir_activTypeDoc_22 = 22,
            [Description("sir_org_23 элемент")]
            sir_org_23 = 23,
            [Description("sir_tag_rd_24 элемент")]
            sir_tag_rd_24 = 24,
            [Description("editParam_date_25 элемент")]
            editParam_date_25 = 25,
            [Description("sir_nd_26 элемент")]
            sir_nd_26 = 26,
            [Description("sir_org_sf_27 элемент")]
            sir_org_sf_27 = 27,
            [Description("sir_td_cod123_28 элемент")]
            sir_td_cod123_28 = 28,
            [Description("sir_td_tag_29 элемент")]
            sir_td_tag_29 = 29,
            [Description("sir_td_tag2_30 элемент")]
            sir_td_tag2_30 = 30,
            [Description("sir_path_to_skladMay_31 элемент")]
            sir_path_to_skladMay_31 = 31,
            [Description("size_font_in_GRID_find_32 элемент")]
            size_font_in_GRID_find_32 = 32,
            [Description("zakaz_defaultValue_33 элемент")]
            zakaz_defaultValue_33 = 33,
            [Description("zakaz_defaultValue_price_34 элемент")]
            zakaz_defaultValue_price_34 = 34,
            [Description("tree_position_Width_35 элемент")]
            tree_position_Width_35 = 35,
            [Description("tree_position_Height_36 элемент")]
            tree_position_Height_36 = 36,
            [Description("tree_position_Width_TOV_37 элемент")]
            tree_position_Width_TOV_37 = 37,
            [Description("tree_MODE_WAED_38 элемент")]
            tree_MODE_WAED_38 = 38,
            [Description("show_fiskal_doc_888show_0hide_39 элемент")]
            show_fiskal_doc_888show_0hide_39 = 39
        }
    }
    namespace TextGlow.Control.Utilities
    {
        public static class EnumUtils
        {
            public static void sdf()
            {
            }

            public static T[] EnumToArray<T>() where T : struct
            {
                //get the enumeration type
                Type et = typeof(T);
                T defaultValue = default(T);

                //get the public static fields (members of the enum)
                FieldInfo[] fi = et.GetFields(BindingFlags.Static | BindingFlags.Public);

                //create a new enum array
                T[] values = new T[fi.Length];

                //populate with the values
                for (int i = 0; i < fi.Length; i++)
                {
                    values[i] = (T)fi[i].GetValue(defaultValue);
                }

                //return the array
                return values;
            }
        }
    }
    public static class Enum<T>
    {

        public static T Parse(string value)
        {
            return (T)Enum.Parse(typeof(T), value);
        }
    }

    class readEnum
    {
        public static string GetDescription(Enum value)
        {
            DescriptionAttribute[] da =
                       (DescriptionAttribute[])(value.GetType().
                              GetField(value.ToString()).
                              GetCustomAttributes(typeof(DescriptionAttribute), false));
            return da.Length > 0 ? da[0].Description : value.ToString();
        }
        public static void plp_r2()
        {
            //FieldInfo fi = value.GetType().GetField(value.ToString());
            Type tt = plp_enum.plp.o_l_0.GetType();
            string[] ass = Enum.GetNames(tt);
            Array ar = Enum.GetValues(tt); int i = 0; 
            FieldInfo fi; 

            foreach (string s in ass)
            {
               fi = tt.GetField(s);
               DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
               if (attributes.Length > 0) {m( attributes[0].Description);} else { m(s); }
               i++;
            }
        }

        public static void plp_read()
        {
            Type tt = plp_enum.plp.o_l_0.GetType();
            string[] ass = Enum.GetNames(tt);
            foreach (string s in ass)
            {
               m( GetDescription((plp_enum.plp)Enum.ToObject(tt, int.Parse(s))));
            }
        }

        public static string GetValue_Name_Description(Enum valueo)
        {
            string sd = GetDescription(valueo);
            string sv = Enum.GetName(valueo.GetType(), valueo);
            string si = (Convert.ToInt32( valueo)).ToString();
            return string.Concat(si,";",sv,";",sd);
        }
        public static T ConvertTo<T>(int number)
        {
            return (T)Enum.ToObject(typeof(T), number);
        }

        public static T ConvertTo<T>(string value)
        {

            return (T)Enum.ToObject(typeof(T), int.Parse(value));
        }
        public static void  G77()
        {
            //foreach (Enum eee in city7.plp_enum.plp)
            //{
            //    functionService.shorts.m(eee.ToString());
            //}
           // functionService.shorts.m(Enum.GetUnderlyingType(typeof(city7.plp_enum.plp)));

           

            foreach (city7.plp_enum.plp plpVal in Enum.GetValues(typeof(city7.plp_enum.plp)))
            {

                functionService.shorts.m(plpVal.ToString());

            }
        }

        public  static  void m(object oo)
        {
            System.Windows.Forms.MessageBox.Show(oo.ToString());
        }

        public static void G770(Enum et)
        {
            //foreach (Enum eee in city7.plp_enum.plp)
            //{
            //    functionService.shorts.m(eee.ToString());
            //}
            // functionService.shorts.m(Enum.GetUnderlyingType(typeof(city7.plp_enum.plp)));
            Type tt = et.GetType();
            string[] gn = Enum.GetNames(tt) ;//(EmpType)Enum.Parse(typeof(EmpType), "Manager");

            foreach (string s in gn)
            {
                functionService.shorts.m(Enum.Parse(tt, s));
            }
        }
        public static void G771<T>()
        {
            //foreach (Enum eee in city7.plp_enum.plp)
            //{
            //    functionService.shorts.m(eee.ToString());
            //}
            // functionService.shorts.m(Enum.GetUnderlyingType(typeof(city7.plp_enum.plp)));
            Type tt = typeof(T);//et.GetType();
            string[] gn = Enum.GetNames(tt);//(EmpType)Enum.Parse(typeof(EmpType), "Manager");

            foreach (string s in gn)
            {
                //functionService.shorts.m(Enum.Parse(tt, s));
                functionService.shorts.m(ConvertTo<T>(s));
               // functionService.shorts.m(GetValue_Name_Description(ConvertTo<T>(s)));
            }

        }
        
        
        
        
        //public static string GetV(Enum valueAny)
        //{
        //    Type tt = valueAny.GetType();
        //    System.Array ar = Enum.GetValues(tt);
        //    string[] sa = Enum.GetNames(tt); 
        //    int[] cip = new int[ar.Length]; int j = 0;
        //    foreach (object o in ar)
        //    {
        //        cip[j] = Convert.ToInt32(o); j++;
        //    }

        //    string[] vn = new string[sa.Length];
        //    for (int i = 0; i < sa.Length; i++)
        //    {
        //        vn[i] = string.Concat("-**", sa[i], "**", cip[i]);
        //    }
            
        //}
    }
}
